package com.hy.study.driver;

import com.hy.study.mapper.DistributedCacheMapper;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.net.URI;

/**
 * @author huyong
 * @date 2024 年 02 月 06 日 15:05: 06
 */
public class DistributedCacheDriver {
    public static void main(String[] args) throws Exception {
        final String inputfile = "F:\\study\\Hadoop\\input\\order";
        final String outputfile = "F:\\study\\Hadoop\\output\\result5";
        Job job = Job.getInstance(new Configuration());
        job.setJarByClass(DistributedCacheDriver.class);

        job.setMapperClass(DistributedCacheMapper.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(NullWritable.class);
        // 加载缓存数据 这两个文件需要放在不同的目录，否则缓存文件回被加载两次
        job.addCacheFile(new URI("file:///F:/study/Hadoop/input/cahce/pd.txt"));
        FileInputFormat.addInputPath(job, new Path(inputfile));
        // 这里设置reducer为0 即不需要reducer 阶段了
        job.setNumReduceTasks(0);

        FileOutputFormat.setOutputPath(job, new Path(outputfile));


        boolean completion = job.waitForCompletion(true);
        System.exit(completion ? 1 : 0);
    }
}
